home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / autofind / source / mapdoc.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  7.9 KB  |  220 lines  |  [TEXT/ttxt]

  1. --<<<-
  2. -- Filename: 
  3. --     mapdoc.sx
  4.  
  5. -- Other Files Required:
  6. --     mapwin.sx
  7.  
  8. -- Purpose:  
  9. --     Class definition for the MapDocument class.
  10.  
  11. -- Specialized Classes:  
  12. --     MapDocument
  13.  
  14. -- Instructions to User:
  15. --     Class MapDocument is a ScriptX Document for displaying objects which
  16. --     have a bitmap image, text description and map detail. It consists of two
  17. --     pages, a front page and a map detail page. When the target object of the
  18. --     document changes, the page elements of these pages are automatically updated. 
  19.  
  20. -- Author:
  21. --     Steve Mayer, Felicia Santelli
  22.  
  23. in module Autofinder
  24.  
  25. class MapDocument (Document)
  26. end
  27.  
  28. -- Method init adds all of the pages to the document.
  29. method init self {class MapDocument} #rest args #key media: ->
  30. (
  31.     apply nextMethod self args
  32.     addFrontPage self media
  33.     addMapPage self media
  34.     addNotesPage self media
  35.     return self
  36. )
  37.  
  38. -- Method addFrontPage adds the front page to the document. The front page consists
  39. -- of one page layer, which contains page elements for the image and text, and
  40. -- buttons for navigation. The image page element is an instance of
  41. -- TwoDShape, which presents a graphic repreentation of the document's
  42. -- target object. The text page element is a TextPresenter, which presents a text
  43. -- description of the document's target object.
  44. method addFrontPage self {class MapDocument} media ->
  45. (
  46.     -- Create a page layer for the first page of the document.
  47.     local frontLayer := new PageLayer boundary:(new Rect x2:365 y2:274)
  48.  
  49.     -- Add buttons for map detail, notes, and printing.
  50.     local ac := new ActuatorController space:frontLayer wholeSpace:true
  51.     local mapButton := new PushButton pressedPresenter:media["Map Button"] \
  52.         releasedPresenter:(new twodshape boundary:media["Map Button"].boundary)
  53.     mapButton.x := 4; mapButton.y := 10
  54.     mapButton.activateAction := (authorData button -> goto self 2)
  55.     prepend frontLayer mapButton
  56.     
  57.     local notesButton := new PushButton pressedPresenter:media["Notes Button"] \
  58.         releasedPresenter:(new twodshape boundary:media["Notes Button"].boundary)
  59.     notesButton.x := 4; notesButton.y := 100
  60.     notesButton.activateAction := (authorData button -> goto self 3)
  61.     prepend frontLayer notesButton
  62.  
  63.     local printButton := new PushButton pressedPresenter:media["Print Button"] \
  64.         releasedPresenter:(new twodshape boundary:media["Print Button"].boundary)
  65.     printButton.x := 4; printButton.y := 190
  66.     printButton.activateAction := (authorData button -> printWindow self.presentedBy)
  67.     prepend frontLayer printButton
  68.  
  69.     -- Create a page element for the image and add it to the page layer.
  70.     local imageElement := new PageElement \
  71.         presenter:(new TwoDShape boundary:(new Rect x2:200 y2:163)) \
  72.         target:(e ->
  73.         (
  74.             local current := getParentData e Document
  75.             return current.adPic
  76.         ))
  77.     translate imageElement.transform 120 10
  78.     prepend frontLayer imageElement
  79.     
  80.     -- Create a bounding box for the text and add it to the page layer.
  81.     local boxBrush := new Brush color:blackColor
  82.     boxBrush.lineWidth := 2
  83.     local textBoundary := new TwoDShape boundary:(new Rect x2:200 y2:84) stroke:boxBrush
  84.     translate textBoundary.transform 120 180
  85.     prepend frontLayer textBoundary
  86.     
  87.     -- Create a page element for the text and add it to the page layer.
  88.     local t := new TextPresenter boundary:(new Rect x2:190 y2:83) target:("" as Text) \
  89.         brush:blackBrush
  90.     setDefaultAttr t @font (new PlatformFont name:"Palatino")
  91.     setDefaultAttr t @leading 12
  92.     setDefaultAttr t @size 12
  93.  
  94.     local textElement := new PageElement presenter:t \
  95.         target:(e ->
  96.         (
  97.             local current := getParentData e Document
  98.             return current.adText
  99.         ))
  100.     translate textElement.transform 123 181
  101.     prepend frontLayer textElement
  102.     
  103.     -- Create a new page with the image/text layer and add it to the document.
  104.     local frontPage := new Page boundary:frontLayer.boundary frame:frontLayer
  105.     append self frontPage
  106. )
  107.  
  108. -- The map detail page consists of one page layer, which contains a page element for
  109. -- the map detail image and a push button for returning to the front page.
  110. method addMapPage self {class MapDocument} media ->
  111. (
  112.     -- Create a page layer for the detail map page of the document.
  113.     local mapLayer := new PageLayer boundary:(new Rect x2:365 y2:274)
  114.  
  115.     -- Add buttons for map detail, notes, and printing.
  116.     local ac := new ActuatorController space:mapLayer wholeSpace:true
  117.     local carButton := new PushButton pressedPresenter:media["Car Button"] \
  118.         releasedPresenter:(new twodshape boundary:media["Car Button"].boundary)
  119.     carButton.x := 4; carButton.y := 30
  120.     carButton.activateAction := (authorData button -> goto self 1)
  121.     prepend mapLayer carButton
  122.     
  123.     local notesButton := new PushButton pressedPresenter:media["Notes Button"] \
  124.         releasedPresenter:(new twodshape boundary:media["Notes Button"].boundary)
  125.     notesButton.x := 4; notesButton.y := 100
  126.     notesButton.activateAction := (authorData button -> goto self 3)
  127.     prepend mapLayer notesButton
  128.  
  129.     local printButton := new PushButton pressedPresenter:media["Print Button"] \
  130.         releasedPresenter:(new twodshape boundary:media["Print Button"].boundary)
  131.     printButton.x := 4; printButton.y := 190
  132.     printButton.activateAction := (authorData button -> printWindow self.presentedBy)
  133.     prepend mapLayer printButton
  134.  
  135.     -- Create a page element for the map and add it to the page layer.
  136.     local mapElement := new PageElement \
  137.         presenter:(new CostumedPresenter boundary:(new Rect x2:288 y2:274)) \
  138.         target:(e ->
  139.         (
  140.             local current := getParentData e Document
  141.             current.mapPresenter.x := -1
  142.             current.mapPresenter.y := -1
  143.             return current.mapPresenter
  144.         ))
  145.  
  146.     translate mapElement.transform 79 1
  147.     append mapLayer mapElement
  148.     
  149.     -- Create a new page with the map layer and add it to the document.
  150.     local mapPage := new Page boundary:mapLayer.boundary frame:mapLayer
  151.     append self mapPage
  152. )
  153.  
  154. -- The notes detail page consists of one page layer, which contains a page element for
  155. -- the notes and a push button for returning to the front page.
  156. method addNotesPage self {class MapDocument} media ->
  157. (
  158.     -- Create a page layer for the notes page of the document.
  159.     local notesLayer := new PageLayer boundary:(new Rect x2:365 y2:274)
  160.  
  161.     -- Add buttons for map detail, notes, and printing.
  162.     local ac := new ActuatorController space:notesLayer wholeSpace:true
  163.     local carButton := new PushButton pressedPresenter:media["Car Button"] \
  164.         releasedPresenter:(new twodshape boundary:media["Car Button"].boundary)
  165.     carButton.x := 4; carButton.y := 30
  166.     carButton.activateAction := (authorData button -> goto self 1)
  167.     prepend notesLayer carButton
  168.     
  169.     local mapButton := new PushButton pressedPresenter:media["Map Button"] \
  170.         releasedPresenter:(new twodshape boundary:media["Map Button"].boundary)
  171.     mapButton.x := 4; mapButton.y := 100
  172.     mapButton.activateAction := (authorData button -> goto self 2)
  173.     prepend notesLayer mapButton
  174.  
  175.     local printButton := new PushButton pressedPresenter:media["Print Button"] \
  176.         releasedPresenter:(new twodshape boundary:media["Print Button"].boundary)
  177.     printButton.x := 4; printButton.y := 190
  178.     printButton.activateAction := (authorData button -> printWindow self.presentedBy)
  179.     prepend notesLayer printButton
  180.  
  181.     -- Create a page element for the notes and add it to the page layer.
  182.     local notesEditer := new textEdit boundary:(new Rect x2:285 y2:270) \
  183.         target:(new text string:"") stroke:blackbrush
  184.     local notesElement := new PageElement \
  185.         presenter:notesEditer boundary:notesEditer.boundary \
  186.         target:(e ->
  187.         (
  188.             local current := getParentData e Document
  189.             return current.adNotes
  190.         ))
  191.  
  192.     translate notesElement.transform 79 3
  193.     append notesLayer notesElement
  194.     
  195.     -- Create a new page with the notes layer and add it to the document.
  196.     local notesPage := new Page boundary:notesLayer.boundary frame:notesLayer
  197.     append self notesPage
  198. )
  199.  
  200. method changePage self {class MapDocument} pg ->
  201. (
  202.     local prev := self.data
  203.     
  204.     nextMethod self pg
  205.     makePurgeable prev.adPic
  206.     makePurgeable prev.mapPresenter
  207. )
  208.  
  209. method leaveScene self {class MapDocument} ->
  210. (
  211.     local item := self.data
  212.  
  213.     emptyout self
  214.     makePurgeable item.adPic
  215.     makePurgeable item.mapPresenter
  216. )
  217.  
  218. -->>>
  219. "Compiled mapdoc.sx"
  220.